﻿using AuthenticationCenter.Utility;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http.Json;
using System.Threading.Tasks;

namespace AuthenticationCenter.Controllers
{
  [Route("api/[controller]")]
  [ApiController]
  public class AuthenticationController : ControllerBase
  {
    private ICustomJWTService _customJWTService = null;
    public AuthenticationController(ICustomJWTService customJWTService)
    {
      _customJWTService = customJWTService;
    }
    [Route("login")]
    [HttpPost]
    public string login(string name, string password)
    {
      if ("fgb".Equals(name) && "123456".Equals(password))
      {
        string token = string.Empty;
        //CustomHSJWTService customHSJWTService = new CustomHSJWTService();
        token = _customJWTService.GetToken(name, password);
        return JsonConvert.SerializeObject(new
        {
          result = true,
          token = token
        });
      }
      else
      {
        return JsonConvert.SerializeObject(new
        {
          result = false
        });
      }
    }
  }
}
